package br.com.caelum.vraptor.interceptor.autentication;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;

import br.com.caelum.vraptor.AroundCall;
import br.com.caelum.vraptor.Intercepts;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.auth_annotations.EmpresaAdmin;
import br.com.caelum.vraptor.components.UsuarioSession;
import br.com.caelum.vraptor.controller.IndexController;
import br.com.caelum.vraptor.interceptor.AcceptsWithAnnotations;
import br.com.caelum.vraptor.interceptor.SimpleInterceptorStack;

@Intercepts
@RequestScoped
@AcceptsWithAnnotations(EmpresaAdmin.class)
public class EmpresaAdminInterceptor {
@Inject
	private UsuarioSession usuarioSession;

@Inject
private Result result;

@AroundCall
public void around(SimpleInterceptorStack stack) {
	
	if (usuarioSession.isLogado() && usuarioSession.getUsuario().getPerfil().getId() == 3) { //Faz duas verifica��es: se o usu�rio est� logado e, se estiver logado, se possui o perfil de escola
		stack.next();
	}
	else { //Caso o usu�rio n�o esteja logado ou, mesmo que esteja, n�o seja escola, redireciona
		result.redirectTo(IndexController.class).index();
	}
}

}
